const Router = require('koa-router');

const momentRouter = new Router({prefix: '/moment'});

const {
    create,
    detail,
    list,
    update,
    deleteDate,
    addLabels,
    fileInfo
} = require('../controller/moment.controller');

const { 
    verifyAuth,
    verifyPermission 
} = require('../middleware/auth.middleware');

const {
    verifyLabelExists
}= require('../middleware/label.middleware');

momentRouter.post('/', verifyAuth, create);     //用户发表动态接口
momentRouter.get('/', list)                //批量查询接口
momentRouter.get('/:conmentId', detail);     //数据id查询接口

//这两个接口必须要满足两个条件1.用户必须登录 2。用户具备权限
momentRouter.patch('/:momentId', verifyAuth, verifyPermission, update);      //用户更新动态接口
momentRouter.delete('/:momentId', verifyAuth, verifyPermission, deleteDate);      //注：delete在js中是关键字，所以不要使用delete来命名中间件

//给动态添加标签
momentRouter.post('/:momentId/labels', verifyAuth, verifyPermission, verifyLabelExists, addLabels);



//动态的配图服务
momentRouter.get('/images/:filename', fileInfo);


module.exports = momentRouter;